//
//  NetworkManager.h
//  KIASupervisory
//
//  Created by tan_xin on 14-7-9.
//  Copyright (c) 2014年 MyCompany. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "ASIHTTPRequest.h"
#import "ASIFormDataRequest.h"
#import "Reachability.h"
#import "Constants.h"

@protocol NetworkManagerDelegate;
@interface NetworkManager : NSObject <ASIHTTPRequestDelegate>

@property (nonatomic, weak) id<NetworkManagerDelegate> delegate;
@property (nonatomic, assign, readonly) RequestMethodId methodId;
@property (nonatomic, assign) BOOL isCancelled;
@property (nonatomic, strong) NSMutableDictionary *requestDict;

// 判断是不是有网络
+(BOOL)connectedToNetwork;

- (BOOL)requestWithMethod:(RequestMethodId)method parameter:(id)param delegate:(id)delegate;
- (BOOL)requestWithMethod2:(RequestMethodId)method parameter:(id)param delegate:(id)delegate;
- (BOOL)cancelRequest;

@end

@protocol NetworkManagerDelegate <NSObject>
@optional
/**
 *  请求成功的回调方法
 *
 *  @param net      发送请求的对象
 *  @param methodId 方法id
 *  @param data     返回数据
 */
- (void)network:(NetworkManager *)net methodId:(RequestMethodId)methodId didRequestFinishedWithResult:(id)data;
/**
 *  请求失败的回调方法
 *
 *  @param net      发送请求的对象
 *  @param methodId 请求方法id
 *  @param error    错误
 */
- (void)network:(NetworkManager *)net methodId:(RequestMethodId)methodId didRequestFailedWithError:(NSError *)error;
@end
